import Base from "./Base";
import utils from 'src/utils'
import { Props } from "src/types/shape";
export default class extends Base {
    constructor(option: Props) {
        super()
        utils.object.Assign(option, this.props)
    }
    draw(ctx: CanvasRenderingContext2D, osCtx: OffscreenCanvasRenderingContext2D): void {
        const { x, y, size, width, height, lineHeight, textObj } = this.props
        if (!ctx || !osCtx) return

        ctx.save()
        this.transform(ctx)
        ctx.translate(width / 2, height / 2)
        ctx.beginPath()
        this.initOptions(ctx, 1)

        textObj.forEach((item, i) => {
            item.forEach((v: any) => {
                if (v.type == 'select') {
                    ctx.fillStyle = "blue"
                    ctx.fillRect(x + v.len * size, y + ((i + 1) * lineHeight) - lineHeight, size * v.text.length, lineHeight + 5)
                    ctx.fillStyle = "white"
                    ctx.fillText(v.text, x + v.len * size, (y + ((i + 1) * lineHeight)))
                } else {
                    ctx.fillStyle = "black"
                    ctx.fillText(v.text, x + v.len * size, (y + ((i + 1) * lineHeight)))
                }
            })
        })
        ctx.closePath()
        ctx.stroke()
        ctx.restore()
        this.drawMirror(osCtx)
    }
    setProps(option: Props): void {
        super.setProps(option)
        // this.props.x += this.props.width / 2
        // this.props.y += this.props.height / 2
    }
}